import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Cpu extends TestingSystem {

        private int CoreNumber;
        private String CoreMask;
        private int NumaNode;
        private CpuUsage CpuUsage;
             
        public Cpu( int coreNumber )
        {       SetCoreMask( coreNumber );
        	SetNumaNode( coreNumber );
        	SetCoreNumber( coreNumber );
        	CpuUsage = new CpuUsage( coreNumber );	}

        public CpuUsage getCpuUsage() 
        {    return CpuUsage;	}

	public void setCpuUsage(CpuUsage cpuUsage) 
	{    CpuUsage = cpuUsage;	}

	public int GetCoreNumber()
	{	return CoreNumber;      }

        public void SetCoreNumber(int coreNumber) 
        {       CoreNumber = coreNumber;        }

        public String GetCoreMask() 
                {       return CoreMask;        }

        public void SetCoreMask(int coreNumber) 
                {       CoreMask = "0x" + Integer.toHexString((int)Math.pow(2,coreNumber));             }

        public int GetNumaNode()
                {       return NumaNode;        }

        public void SetNumaNode(int coreNumber)
        {
                Pattern pattern = Pattern.compile("node\\s+(\\d+)\\s+cpu:\\s+(.+)");
                Matcher matcher = pattern.matcher(getNumactl_hardware());

                while (matcher.find())
                {
                        String[] St = (matcher.group(2)).toString().split("\\s+");
                        for ( String st : St )
                        {
                                if (Integer.parseInt(st) == coreNumber)
                                {       NumaNode = Integer.parseInt(matcher.group(1).toString());
                                        break;
                                }
                        }
                }
        }


}
